package com.design.pattern.principle.dependencyInversion.improve;

public class DependencyInversion {
    //客户端代码无需改变
    public static void main(String[] args) {
        new Person().receive(new Email());
        new Person().receive(new WeiXin());
    }
}

interface IReceiver {
    String getInfo();
}

class Email implements IReceiver {
    @Override
    public String getInfo() {
        return "电子邮件信息：Hello,World";
    }
}

class WeiXin implements IReceiver {

    @Override
    public String getInfo() {
        return "微信消息：Hello,ok";
    }
}

/**
 * 好处：此使依赖的是接口，如果接口无变化，则对于依赖它的Person无影响
 */
class Person {
    /**
     * 对接口的依赖
     *
     * @param iReceiver 接收的消息
     */
    public void receive(IReceiver iReceiver) {
        System.out.println(iReceiver.getInfo());
    }
}